﻿CREATE TABLE [lov].[Row] (
    [Id]         UNIQUEIDENTIFIER DEFAULT (newid()) NOT NULL,
    [EntityId]   INT              NOT NULL,
    [AddDate]    DATETIME         CONSTRAINT [DF_Row_AddDate] DEFAULT (getdate()) NULL,
    [UpdateDate] DATETIME         CONSTRAINT [DF_Row_UpdateDate] DEFAULT (getdate()) NULL,
    [DeleteDate] DATETIME         NULL,
    [AddBy]      VARCHAR (128)    NULL,
    [UpdateBy]   VARCHAR (128)    NULL,
    [DeleteBy]   VARCHAR (128)    NULL,
    CONSTRAINT [PK_Row] PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT [FK_Row_Entity] FOREIGN KEY ([EntityId]) REFERENCES [lov].[Entity] ([Id]) ON DELETE CASCADE
);




GO
CREATE NONCLUSTERED INDEX [idx_Deleted]
    ON [lov].[Row]([EntityId] ASC, [DeleteDate] ASC)
    INCLUDE([Id]);


GO
CREATE NONCLUSTERED INDEX [idx_EntityId]
    ON [lov].[Row]([EntityId] ASC)
    INCLUDE([Id], [AddDate], [UpdateDate]);

